<template>
  <el-image :src="imgPath" :v-lazy="imgPath" class="van_img" :round="round" @click="previewImage(imgPath)" :alt="alt">
    <div slot="placeholder" class="image-slot">
      <img src="@/assets/images/placeholder.png" alt="" />
    </div>
    <div slot="error" class="image-slot">
      <i class="el-icon-picture-outline"></i>
    </div>
  </el-image>
</template>
<script>
import { api as viewerApi } from "v-viewer";
import "viewerjs/dist/viewer.css";
import config from "@/http/config";
import { Image } from "element-ui";
export default {
  name: "LiImage",
  props: {
    src: {
      type: String,
      default: "",
    },
    lazyLoad: {
      type: Boolean,
      default: true,
    },
    round: {
      type: Boolean,
      default: false,
    },
    isPreview: {
      type: Boolean,
      default: false,
    },
    fit: {
      type: String,
      default: "fill",
    },
    alt:{
      type:String,
      default:''
    }
  },
  components: {
    [Image.name]: Image,
  },
  watch: {
    src: {
      handler: function (n) {
        if (n) {
          this.imgPath = this.IMAGEURL + n;
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      IMAGEURL: config.IMAGEURL,
      imgPath: "",
    };
  },
  methods: {
    // 图片预览
    previewImage(path) {
      let imageList = [path]
      if (this.isPreview) {
        viewerApi({
          images: imageList,
          options: {
            zIndex: 99999,
          },
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.van_img {
  width: 100%;
  height: 100%;

  .image-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #f5f7fa;
    font-size: 50px;
    color: #909399;

    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>